package tech.aistar.service.impl;

import tech.aistar.dao.IVideoDao;
import tech.aistar.dao.IVideoDao2;
import tech.aistar.dao.impl.VideoDaoImpl;
import tech.aistar.dao.impl.VideoDaoImpl2;
import tech.aistar.model.dto.PageInfo;
import tech.aistar.model.pojo.Video;
import tech.aistar.service.IVideoService;

import java.util.List;

/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2022/8/12 1:44 下午
 */
public class VideoServiceImpl implements IVideoService {
    private IVideoDao2 videoDao = new VideoDaoImpl2();
    @Override
    public PageInfo<Video> listPage(String title, Integer pageNum, Integer pageSize) {
        PageInfo<Video> pageInfo = new PageInfo<>();

        //判断title的非法性
        if(null==title || title.trim().length()==0){
            title="";
        }
        pageNum = pageNum==null?1:pageNum;
        pageSize = pageSize==null?3:pageSize;
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);

        List<Video> videoList = videoDao.find(title,pageNum,pageSize);
        pageInfo.setData(videoList);

        //总的条数
        Integer rows = videoDao.countRows(title);
        pageInfo.setRows(rows);

        //总的页数
        Integer pageTotal = rows/pageSize;
        if(rows%pageSize!=0)
            pageTotal++;

        pageInfo.setPageTotal(pageTotal);

        return pageInfo;
    }
}
